﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Sinacor.Infra.UI.Controls.SmartClient.BehaviorPolicy;
using Sinacor.Infra.UI.Controls.SmartClient.Validation;
using System.Collections.ObjectModel;
using System.Windows;
using Sinacor.Infra.UI.Controls.SmartClient.DataGrid;
using System.Windows.Markup;
using System.Globalization;

namespace Sinacor.Infra.UI.Controls.SmartClient
{
    public class SinacorTextBlock : TextBlock
    {
        public SinacorTextBlock()
        {
            // É necessário configurar o language manualmente para o TextBlock devido a um 
            // problema para formatar valores dentro do DataGrid2
            this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name);
        }

        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {
            base.OnVisualParentChanged(oldParent);

            // Aplica um estilo diferenciado caso esteja dentro de uma célula ou tooltip

            bool applyStyle = false;

            if (ControlHelper.FindParent(this, typeof(DataGridCell)) != null)
            {
                applyStyle = true;
            }
            else
            {
                ToolTip toolTip = ControlHelper.FindParent(this, typeof(ToolTip)) as ToolTip;
                if (toolTip != null &&
                    toolTip.PlacementTarget is DataGridCell)
                {
                    applyStyle = true;
                }
            }

            if (applyStyle)
            {
                this.SetResourceReference(FrameworkElement.StyleProperty, "ControlDataGridSinacorTextBlock");
            }
        }
    }
}
